package wizard;

import java.util.Enumeration;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextField;
import javax.microedition.pim.Contact;
import javax.microedition.pim.ContactList;
import javax.microedition.pim.PIM;

/**
 * Wizard Design Pattern.
 * Wizard dialog 1.
 *
 * @author Ben Hui
 */

public class WPage1 extends WDialog
{
	
//private ContactList contList = null;

 private Enumeration contacts = null;

 private List mNameList;

  
 
	
  public WPage1()
  {
  }

  public void initDialog()
  {
	  setTitle("Lista de Contactos");
	  
	      //mNameList.addCommand(mExitCommand);
	      //mNameList.setCommandListener(this);

    
  }
  public int onEnter( int dir ){
	  setTitle("Lista de Contactos");
	  try {
	      PIM pimInst = PIM.getInstance();
	      Wizardlet.instance.contList = (ContactList) pimInst.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
	      contacts = Wizardlet.instance.contList.items();
	      mNameList = new List("List of contacts", List.EXCLUSIVE);
	    } catch (Exception ex) {
	    	return WDialog.OK;;
	    }

	    
	    if (contacts == null)
	    	return WDialog.OK; ;
	      mNameList = new List("List of contacts", List.EXCLUSIVE);
	      while (contacts.hasMoreElements()) {
	        Contact tCont = (Contact) contacts.nextElement();
	        String[] nameValues = tCont.getStringArray(Contact.NAME, 0);
	        String firstName = nameValues[Contact.NAME_GIVEN];
	        String lastName = nameValues[Contact.NAME_FAMILY];
	        mNameList.append(lastName + ", " + firstName, null);
	      }
	      return WDialog.OK;
  }
  

  

  
  
}